import tool from "/src/utils/tool.js";

const AsciiToString = code => {
    return tool.AsciiToString(code);
};

window.alert = function (msg) {
    var str = "";

    for (var i = 0; i < msg.length; i += 1) {
        var s = msg.charAt(i);

        if (s === "+") {
            str += " ";
        } else {
            if (s === "%") {
                var hex = msg.substring(i + 1, i + 3);

                parseInt("0x" + hex) > 127 ? (str += decodeURI("%" + hex.toString() + msg.substring(i + 3, i + 9).toString()), i += 8) : (str += AsciiToString(parseInt("0x" + hex)), i += 2);
            } else {
                str += s;
            }
        }
    }

    return false;
};

const urlDecode = url => {
        return tool.urlDecode(url);
    },
    getUrlParams = url => {
        return tool.getUrlParams(url);
    },
    getFactor = e => {
        return tool.getFactor(e);
    },
    initBackground = (backgroundObject, scaleFactor) => {
        return tool.initBackground(backgroundObject, scaleFactor);
    },
    initTitle = (titleImage, scaleFactor) => {
        return tool.initTitle(titleImage, scaleFactor);
    },
    initMyInputContainer = (containerImage, contentImage, scaleFactor) => {
        return tool.initMyInputContainer(containerImage, contentImage, scaleFactor);
    },
    initJoinBoxContainer = (containerImage, iconImages, langGetter, scaleFactor) => {
        return tool.initJoinBoxContainer(containerImage, iconImages, langGetter, scaleFactor);
    },
    initEvadedFail = (failImage, langGetter, scaleFactor) => {
        return tool.initEvadedFail(failImage, langGetter, scaleFactor);
    },
    initEvadedSuccess = (successImage, langGetter, scaleFactor) => {
        return tool.initEvadedSuccess(successImage, langGetter, scaleFactor);
    },
    initEvadedWait = (waitImage, langGetter, killerAmount, scaleFactor) => {
        return tool.initEvadedWait(waitImage, langGetter, killerAmount, scaleFactor);
    },
    initHomeMedal = (medalIndex, medalImage, medalPositions, scaleFactor) => {
        return tool.initHomeMedal(medalIndex, medalImage, medalPositions, scaleFactor);
    },
    initHovel = (hovelImage, scaleFactor) => {
        return tool.initHovel(hovelImage, scaleFactor);
    },
    initHovelText = (hovelTextImage, scaleFactor) => {
        return tool.initHovelText(hovelTextImage, scaleFactor);
    },
    initOffice = (officeImage, scaleFactor) => {
        return tool.initOffice(officeImage, scaleFactor);
    },
    initOfficeText = (officeTextImage, scaleFactor) => {
        return tool.initOfficeText(officeTextImage, scaleFactor);
    },
    initLounge = (loungeImage, scaleFactor, hovelDimensions) => {
        return tool.initLounge(loungeImage, scaleFactor, hovelDimensions);
    },
    initLoungeText = (loungeTextImage, scaleFactor, hovelDimensions) => {
        return tool.initLoungeText(loungeTextImage, scaleFactor, hovelDimensions);
    },
    initSpeak = (scaleFactor, assets) => {
        return tool.initSpeak(scaleFactor, assets);
    },
    initSpeakText = assets => {
        return tool.initSpeakText(assets);
    },
    initLaundry = assets => {
        return tool.initLaundry(assets);
    },
    initLaundryText = assets => {
        return tool.initLaundryText(assets);
    },
    initStudio = assets => {
        return tool.initStudio(assets);
    },
    initStudioText = assets => {
        return tool.initStudioText(assets);
    },
    initTea = assets => {
        return tool.initTea(assets);
    },
    initTeaText = assets => {
        return tool.initTeaText(assets);
    },
    initMusic = assets => {
        return tool.initMusic(assets);
    },
    initMusicText = assets => {
        return tool.initMusicText(assets);
    },
    initDoors = assets => {
        tool.initDoors(assets);
    },
    initKiller = gameContext => {
        tool.initKiller(gameContext);
    },
    initMonkey = (userInfo, walkDelay = 0, gameContext) => {
        let monkeyKey = "monkey_" + gameContext.info.game_id + "_" + userInfo.user_id;

        if (gameContext.userMonkeys.hasOwnProperty(monkeyKey)) {
            if (!(userInfo.user_id == gameContext.refreshInfo.user_id)) {
                if (!gameContext.userMonkeys[monkeyKey].walk && userInfo.room_id) {
                    gameContext.userMonkeys[monkeyKey].walk = true;
                    gameContext.userMonkeys[monkeyKey].home_id = userInfo.room_id;
                    setTimeout(() => {
                        gameContext.userMonkeyWalk(gameContext.userMonkeys[monkeyKey].target, userInfo.room_id, walkDelay);
                    }, Math.random() * 1000);
                } else {
                    gameContext.userMonkeys[monkeyKey].walk && userInfo.room_id != gameContext.userMonkeys[monkeyKey].home_id && (gameContext.userMonkeys[monkeyKey].home_id = userInfo.room_id, gameContext.userMonkeys[monkeyKey].walkOver && gameContext.userMonkeyWalk(gameContext.userMonkeys[monkeyKey].target, userInfo.room_id, 0));
                }
            }

            return;
        }

        let monkeyBitmap = new createjs.Bitmap(gameContext.loader.getResult("monkey_0_0")),
            monkeyWidth = monkeyBitmap.image.width,
            monkeyHeight = monkeyBitmap.image.height;

        if (!gameContext.monkeysBuilder) {
            var spriteSheetBuilder = new createjs.SpriteSheetBuilder(),
                frameArray = [];

            for (let frameIndex = 0; frameIndex < 60; frameIndex++) {
                frameArray.push(spriteSheetBuilder.addFrame(new createjs.Bitmap(gameContext.loader.getResult("monkey_0_" + frameIndex))));
            }

            spriteSheetBuilder.addAnimation("stand", frameArray, "stand", 0.5);

            gameContext.monkeysBuilder = spriteSheetBuilder.build();
        }

        let clonedSprite,
            scaleFactor = 1;

        if (!gameContext.userMonkeysTarget) {
            var spriteSheet = gameContext.monkeysBuilder;
            const scalingOptions = {
                scaleX: gameContext.factor * 0.4 * scaleFactor,
                scaleY: gameContext.factor * 0.4 * scaleFactor
            };
            clonedSprite = new createjs.Sprite(spriteSheet, "stand").set(scalingOptions);
            gameContext.userMonkeysTarget = clonedSprite.clone();
        } else {
            clonedSprite = gameContext.userMonkeysTarget.clone();
        }

        clonedSprite.x = 0;
        clonedSprite.y = 50 * gameContext.factor * scaleFactor;
        clonedSprite.regX = monkeyWidth / 2;
        clonedSprite.regY = monkeyHeight / 2;
        Math.random() * 10 > 5 && (clonedSprite.skewY = -180);

        let monkeyContainer = new createjs.Container();

        monkeyContainer.x = Math.random() * (window.innerWidth - 200 * gameContext.factor) + 50 * gameContext.factor;
        monkeyContainer.y = gameContext.tea.y + (gameContext.tea.image.height + Math.random() * 100 + 100) * gameContext.factor;
        monkeyContainer.x_o = monkeyContainer.x;
        monkeyContainer.y_o = monkeyContainer.y;

        let userNameText = new createjs.Text(userInfo.user_id == gameContext.refreshInfo.user_id ? gameContext.$t("lang22") : userInfo.nickname, "bold " + 60 * gameContext.factor * scaleFactor * 0.4 + "px Arial", "#FFFFFF");

        userNameText.shadow = new createjs.Shadow("#000000", 2, 0, 1);
        userNameText.textAlign = "center";

        userNameText.setBounds(0, 0, monkeyWidth * (gameContext.factor * 0.4 * scaleFactor), 20 * gameContext.factor * scaleFactor * 0.4);

        monkeyContainer.addChildAt(userNameText, 0);

        monkeyContainer.addChildAt(clonedSprite, 1);

        monkeyContainer.flowScale = scaleFactor;
        monkeyContainer.monkeyWidth = monkeyWidth;
        monkeyContainer.monkeyHeight = monkeyHeight;
        monkeyContainer.scale = 0;
        monkeyContainer.user_id = userInfo.user_id;

        gameContext.userMonkeysContainer.addChild(monkeyContainer);

        const scaleTween = {
            scale: 1
        };
        createjs.Tween.get(monkeyContainer).to(scaleTween, 100);
        userInfo.user_id == gameContext.refreshInfo.user_id && (gameContext.myMonkey = monkeyContainer);
        const monkeyInfo = {
            target: monkeyContainer,
            home_id: userInfo.home_id,
            walk: false,
            walkOver: false,
            user_id: userInfo.user_id,
            out: false
        };
        gameContext.userMonkeys[monkeyKey] = monkeyInfo;
        userInfo.room_id && userInfo.user_id != gameContext.refreshInfo.user_id && (gameContext.userMonkeys[monkeyKey].walk = true, gameContext.userMonkeys[monkeyKey].home_id = userInfo.home_id, setTimeout(() => {
            gameContext.userMonkeyWalk(gameContext.userMonkeys[monkeyKey].target, userInfo.room_id, walkDelay);
        }, Math.random() * 1000));

        if (walkDelay == 0 && userInfo.user_id == gameContext.refreshInfo.user_id) {
            gameContext.homeClick(userInfo.room_id);
        }
    },
    initBtnActions = gameInfo => {
        tool.initBtnActions(gameInfo);
    },
    initOtherActions = gameInfo => {
        tool.initOtherActions(gameInfo);
    },
    initHomeSelectMask = homeInfo => {
        tool.initHomeSelectMask(homeInfo);
    },
    showKillerTips = (gameContext, callback) => {
        let container = new createjs.Container(),
            overlayGraphics = new createjs.Graphics().beginFill("#00000077").drawRect(0, 0, window.innerWidth, document.body.clientHeight);

        var overlayShape = new createjs.Shape(overlayGraphics);

        container.addChild(overlayShape);

        gameContext.stage.addChild(container);

        let killerBitmap = new createjs.Bitmap(gameContext.loader.getResult("killerAppears_" + gameContext.lang)).set({
            scaleX: gameContext.factor,
            scaleY: gameContext.factor
        });

        killerBitmap.alpha = 0;
        killerBitmap.x = window.innerWidth / 2 - killerBitmap.image.width * gameContext.factor / 2;
        killerBitmap.y = window.innerHeight / 2 - killerBitmap.image.height * gameContext.factor / 2;
        killerBitmap.regX = 0;
        killerBitmap.regY = killerBitmap.image.height * gameContext.factor / 2;

        container.addChild(killerBitmap);

        gameContext.killerApearContainer = container;
        const fadeIn = {
            alpha: 1
        };
        const fadeOut1 = {
            alpha: 0.7
        };
        const fadeIn2 = {
            alpha: 1
        };
        const fadeOut2 = {
            alpha: 0.7
        };
        const fadeIn3 = {
            alpha: 1
        };
        createjs.Tween.get(killerBitmap).to(fadeIn, 600).to(fadeOut1, 600).to(fadeIn2, 600).to(fadeOut2, 600).to(fadeIn3, 600).call(e => {
            callback(e);
        });
    },
    closeHoverDoor = gameContext => {
        createjs.Tween.get(gameContext.doorHovelContaner.getChildAt(0)).to({
            x: -5 * gameContext.factor
        }, 500);
    },
    closeLoungeDoor = gameContext => {
        createjs.Tween.get(gameContext.doorLoungeContainer.getChildAt(0)).to({
            x: 5 * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorLoungeContainer.getChildAt(1)).to({
            x: gameContext.doorLoungeContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    closeOfficeDoor = gameContext => {
        const initialPosition = {
            x: 0
        };
        createjs.Tween.get(gameContext.doorOfficeContainer.getChildAt(0)).to(initialPosition, 500);
        createjs.Tween.get(gameContext.doorOfficeContainer.getChildAt(1)).to({
            x: gameContext.doorOfficeContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    closeLaundryDoor = gameContext => {
        const initialPosition = {
            x: 0
        };
        createjs.Tween.get(gameContext.doorLaundryContainer.getChildAt(0)).to(initialPosition, 500);
        createjs.Tween.get(gameContext.doorLaundryContainer.getChildAt(1)).to({
            x: gameContext.doorLaundryContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    closeMusicDoor = gameContext => {
        const initialPosition = {
            x: 0
        };
        createjs.Tween.get(gameContext.doorMusicContainer.getChildAt(0)).to(initialPosition, 500);
        createjs.Tween.get(gameContext.doorMusicContainer.getChildAt(1)).to({
            x: gameContext.doorMusicContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    closeSpeakDoor = gameContext => {
        const initialPosition = {
            y: 0
        };
        createjs.Tween.get(gameContext.doorSpeakContainer.getChildAt(0)).to(initialPosition, 500);
    },
    closeTeaDoor = gameContext => {
        const initialPosition = {
            y: 0
        };
        createjs.Tween.get(gameContext.doorTeaContainer.getChildAt(0)).to(initialPosition, 500);
    },
    closeStudioDoor = gameContext => {
        const initialPosition = {
            y: 0
        };
        createjs.Tween.get(gameContext.doorStudioContainer.getChildAt(0)).to(initialPosition, 500);
    },
    closeDoor = gameContext => {
        let allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decodedText = tool.monkeyWalkT(encryptedText);

        if (!decodedText) {
            return;
        }

        if (allowedHosts != decodedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        const initialPosition = {
            x: 0
        };
        createjs.Tween.get(gameContext.doorContainer.getChildAt(0)).to(initialPosition, 500);
        createjs.Tween.get(gameContext.doorContainer.getChildAt(1)).to({
            x: (gameContext.doorContainer.getChildAt(1).image.width - 5) * gameContext.factor
        }, 500).call(e => {
            setKillerRoomAndNavigate(gameContext);
        });
    },
    setKillerRoomAndNavigate = gameContext => {
        let killerRoomIndex = gameContext.refreshInfo.killer_room;
        gameContext.killHomeIndex = killerRoomIndex;

        switch (killerRoomIndex) {
            case 1:
                gameContext.goHovel();

                break;

            case 2:
                gameContext.goLounge();

                break;

            case 3:
                gameContext.goOffice();

                break;

            case 4:
                gameContext.goSpeak();

                break;

            case 5:
                gameContext.goLaundry();

                break;

            case 6:
                gameContext.goStudio();

                break;

            case 7:
                gameContext.goTea();

                break;

            case 8:
                gameContext.goMusic();

                break;
        }
    },
    openHovelDoor = gameContext => {
        createjs.Tween.get(gameContext.doorHovelContaner.getChildAt(0)).to({
            x: -gameContext.doorHovelContaner.getChildAt(0).image.width * gameContext.factor
        }, 500);
    },
    openLoungeDoor = gameContext => {
        createjs.Tween.get(gameContext.doorLoungeContainer.getChildAt(0)).to({
            x: 5 * gameContext.factor - gameContext.doorLoungeContainer.getChildAt(0).image.width * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorLoungeContainer.getChildAt(1)).to({
            x: 2 * gameContext.doorLoungeContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    openOfficeDoor = gameContext => {
        createjs.Tween.get(gameContext.doorOfficeContainer.getChildAt(0)).to({
            x: 5 * gameContext.factor - gameContext.doorOfficeContainer.getChildAt(0).image.width * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorOfficeContainer.getChildAt(1)).to({
            x: 2 * gameContext.doorOfficeContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    openSpeakDoor = gameContext => {
        createjs.Tween.get(gameContext.doorSpeakContainer.getChildAt(0)).to({
            y: 90 * gameContext.factor
        }, 500);
    },
    openLaundryDoor = gameContext => {
        createjs.Tween.get(gameContext.doorLaundryContainer.getChildAt(0)).to({
            x: 5 * gameContext.factor - gameContext.doorLaundryContainer.getChildAt(0).image.width * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorLaundryContainer.getChildAt(1)).to({
            x: 2 * gameContext.doorLaundryContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    openStudioDoor = gameContext => {
        createjs.Tween.get(gameContext.doorStudioContainer.getChildAt(0)).to({
            y: 90 * gameContext.factor
        }, 500);
    },
    openTeaDoor = gameContext => {
        createjs.Tween.get(gameContext.doorTeaContainer.getChildAt(0)).to({
            y: 90 * gameContext.factor
        }, 500);
    },
    openMusicDoor = gameContext => {
        createjs.Tween.get(gameContext.doorMusicContainer.getChildAt(0)).to({
            x: 5 * gameContext.factor - gameContext.doorMusicContainer.getChildAt(0).image.width * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorMusicContainer.getChildAt(1)).to({
            x: 2 * gameContext.doorMusicContainer.getChildAt(1).image.width * gameContext.factor - 5 * gameContext.factor
        }, 500);
    },
    openDoor = gameContext => {
        let allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decodedText = tool.monkeyWalkT(encryptedText);

        if (!decodedText) {
            return;
        }

        if (allowedHosts != decodedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        createjs.Tween.get(gameContext.doorContainer.getChildAt(0)).to({
            x: -gameContext.doorContainer.getChildAt(0).image.width * gameContext.factor
        }, 500);
        createjs.Tween.get(gameContext.doorContainer.getChildAt(1)).to({
            x: (2 * gameContext.doorContainer.getChildAt(1).image.width - 5) * gameContext.factor
        }, 500).call(e => {
            gameContext.outMyMonkey();

            gameContext.outAllMonkeys();
        });
    },
    outMonkeyHovel = (hovelObj, speakObj) => {
        hovelObj.getChildAt(1).skewY == -180 && (hovelObj.getChildAt(1).skewY = 0);
        const destination = {
            x: speakObj.speak.x + (speakObj.speak.image.width + 70) * speakObj.factor
        };
        createjs.Tween.get(hovelObj).to(destination, 300).to({
            y: speakObj.speak.y + 40 * speakObj.factor / hovelObj.flowScale
        }, 300).to({
            x: speakObj.studio.x - 80 * speakObj.factor
        }, 500).to({
            y: hovelObj.y_o
        }, 1000).call(e => {
            hovelObj.x_o > speakObj.studio.x - 80 * speakObj.factor && hovelObj.getChildAt(1).skewY != 0 && (hovelObj.getChildAt(1).skewY = 0);

            if (hovelObj.x_o < speakObj.studio.x - 80 * speakObj.factor && hovelObj.getChildAt(1).skewY != -180) {
                hovelObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: hovelObj.x_o
        }, 300).call(e => {
            hovelObj.x_o > speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && hovelObj.getChildAt(1).skewY != 0 && (hovelObj.getChildAt(1).skewY = -180);

            if (hovelObj.x_o < speakObj.studio.x - 80 * speakObj.factor) {
                if (Math.random() * 10 > 5 && hovelObj.getChildAt(1).skewY != 0) {
                    hovelObj.getChildAt(1).skewY = 0;
                }
            }
        });
    },
    outMonkeyLounge = (loungeObj, speakObj) => {
        loungeObj.getChildAt(1).skewY == 0 && (loungeObj.getChildAt(1).skewY = -180);

        let allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decryptedText = tool.monkeyWalkT(encryptedText);

        if (!decryptedText) {
            return;
        }

        if (allowedHosts != decryptedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        const destination = {
            y: speakObj.lounge.y + (speakObj.lounge.image.height - 180) * speakObj.factor
        };
        const offset = {
            x: speakObj.lounge.x + 90 * speakObj.factor
        };
        createjs.Tween.get(loungeObj).to(destination, 300).to(offset, 300).to({
            y: speakObj.speak.y + 40 * speakObj.factor / loungeObj.flowScale
        }, 300).to({
            x: speakObj.studio.x - 80 * speakObj.factor
        }, 500).to({
            y: loungeObj.y_o
        }, 1000).call(e => {
            if (loungeObj.x_o > speakObj.studio.x - 80 * speakObj.factor && loungeObj.getChildAt(1).skewY != 0) {
                loungeObj.getChildAt(1).skewY = 0;
            }

            loungeObj.x_o < speakObj.studio.x - 80 * speakObj.factor && loungeObj.getChildAt(1).skewY != -180 && (loungeObj.getChildAt(1).skewY = -180);
        }).to({
            x: loungeObj.x_o
        }, 300).call(e => {
            loungeObj.x_o > speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && loungeObj.getChildAt(1).skewY != 0 && (loungeObj.getChildAt(1).skewY = -180);
            loungeObj.x_o < speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && loungeObj.getChildAt(1).skewY != 0 && (loungeObj.getChildAt(1).skewY = 0);
        });
    },
    outMonkeyOffice = (officeObj, speakObj) => {
        if (officeObj.getChildAt(1).skewY == 0) {
            officeObj.getChildAt(1).skewY = -180;
        }

        const destination = {
            x: speakObj.studio.x - 10 * speakObj.factor
        };
        const offsetY = {
            y: speakObj.office.y + (speakObj.office.image.height - 150) * speakObj.factor
        };
        const offset = {
            x: speakObj.studio.x - 80 * speakObj.factor
        };
        createjs.Tween.get(officeObj).to(destination, 300).to(offsetY, 300).to(offset, 300).to({
            y: officeObj.y_o
        }, 1000).call(e => {
            officeObj.x_o > speakObj.studio.x - 80 * speakObj.factor && officeObj.getChildAt(1).skewY != 0 && (officeObj.getChildAt(1).skewY = 0);

            if (officeObj.x_o < speakObj.studio.x - 80 * speakObj.factor && officeObj.getChildAt(1).skewY != -180) {
                officeObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: officeObj.x_o
        }, 300).call(e => {
            officeObj.x_o > speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && officeObj.getChildAt(1).skewY != 0 && (officeObj.getChildAt(1).skewY = -180);

            if (officeObj.x_o < speakObj.studio.x - 80 * speakObj.factor) {
                Math.random() * 10 > 5 && officeObj.getChildAt(1).skewY != 0 && (officeObj.getChildAt(1).skewY = 0);
            }
        });
    },
    outMonkeyLaundry = (laundryObj, speakObj) => {
        laundryObj.getChildAt(1).x < speakObj.laundry.x + 200 * speakObj.factor && laundryObj.getChildAt(1).skewY == -180 && (laundryObj.getChildAt(1).skewY = 0);
        laundryObj.getChildAt(1).x > speakObj.laundry.x + 200 * speakObj.factor && laundryObj.getChildAt(1).skewY == 0 && (laundryObj.getChildAt(1).skewY = -180);

        let allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decryptedText = tool.monkeyWalkT(encryptedText);

        if (!decryptedText) {
            return;
        }

        if (allowedHosts != decryptedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        const destination = {
            x: speakObj.laundry.x + 200 * speakObj.factor
        };
        const offsetY = {
            y: speakObj.tea.y + 30 * speakObj.factor
        };
        const offset = {
            x: speakObj.studio.x - 80 * speakObj.factor
        };
        createjs.Tween.get(laundryObj).to(destination, 300).to(offsetY, 300).to(offset, 1000).to({
            y: laundryObj.y_o
        }, 500).call(e => {
            if (laundryObj.x_o > speakObj.studio.x - 80 * speakObj.factor && laundryObj.getChildAt(1).skewY != 0) {
                laundryObj.getChildAt(1).skewY = 0;
            }

            if (laundryObj.x_o < speakObj.studio.x - 80 * speakObj.factor && laundryObj.getChildAt(1).skewY != -180) {
                laundryObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: laundryObj.x_o
        }, 300).call(e => {
            laundryObj.x_o > speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && laundryObj.getChildAt(1).skewY != 0 && (laundryObj.getChildAt(1).skewY = -180);

            if (laundryObj.x_o < speakObj.studio.x - 80 * speakObj.factor) {
                Math.random() * 10 > 5 && laundryObj.getChildAt(1).skewY != 0 && (laundryObj.getChildAt(1).skewY = 0);
            }
        });
    },
    outMonkeyStudio = (studioObj, speakObj) => {
        if (studioObj.getChildAt(1).skewY == 0) {
            studioObj.getChildAt(1).skewY = -180;
        }

        const destination = {
            x: speakObj.studio.x + 30 * speakObj.factor
        };
        const offsetY = {
            y: speakObj.tea.y + 50 * speakObj.factor
        };
        const offset = {
            x: speakObj.studio.x - 80 * speakObj.factor
        };
        createjs.Tween.get(studioObj).to(destination, 300).to(offsetY, 300).to(offset, 300).to({
            y: studioObj.y_o
        }, 500).call(e => {
            studioObj.x_o > speakObj.studio.x - 80 * speakObj.factor && studioObj.getChildAt(1).skewY != 0 && (studioObj.getChildAt(1).skewY = 0);

            if (studioObj.x_o < speakObj.studio.x - 80 * speakObj.factor && studioObj.getChildAt(1).skewY != -180) {
                studioObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: studioObj.x_o
        }, 300).call(e => {
            if (studioObj.x_o > speakObj.studio.x - 80 * speakObj.factor) {
                Math.random() * 10 > 5 && studioObj.getChildAt(1).skewY != 0 && (studioObj.getChildAt(1).skewY = -180);
            }

            studioObj.x_o < speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && studioObj.getChildAt(1).skewY != 0 && (studioObj.getChildAt(1).skewY = 0);
        });
    },
    outMonkeyTea = (teaObj, speakObj) => {
        teaObj.getChildAt(1).skewY == -180 && (teaObj.getChildAt(1).skewY = 0);
        const destination = {
            y: speakObj.tea.y + 60 * speakObj.factor
        };
        const offset = {
            x: speakObj.studio.x - 80 * speakObj.factor
        };
        createjs.Tween.get(teaObj).to(destination, 300).to(offset, 1000).to({
            y: teaObj.y_o
        }, 500).call(e => {
            if (teaObj.x_o > speakObj.studio.x - 80 * speakObj.factor && teaObj.getChildAt(1).skewY != 0) {
                teaObj.getChildAt(1).skewY = 0;
            }

            if (teaObj.x_o < speakObj.studio.x - 80 * speakObj.factor && teaObj.getChildAt(1).skewY != -180) {
                teaObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: teaObj.x_o
        }, 300).call(e => {
            teaObj.x_o > speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && teaObj.getChildAt(1).skewY != 0 && (teaObj.getChildAt(1).skewY = -180);
            teaObj.x_o < speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && teaObj.getChildAt(1).skewY != 0 && (teaObj.getChildAt(1).skewY = 0);
        });
    },
    outMonkeyMusic = (musicObj, speakObj) => {
        musicObj.getChildAt(1).x < speakObj.music.x + (speakObj.music.image.width - 100) * speakObj.factor && musicObj.getChildAt(1).skewY == -180 && (musicObj.getChildAt(1).skewY = 0);
        musicObj.getChildAt(1).x > speakObj.music.x + (speakObj.music.image.width - 100) * speakObj.factor && musicObj.getChildAt(1).skewY == 0 && (musicObj.getChildAt(1).skewY = -180);

        let allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decryptedText = tool.monkeyWalkT(encryptedText);

        if (!decryptedText) {
            return;
        }

        if (allowedHosts != decryptedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        const destination = {
            x: speakObj.music.x + (speakObj.music.image.width - 100) * speakObj.factor
        };
        const offsetY = {
            y: speakObj.tea.y + 60 * speakObj.factor
        };
        const offset = {
            x: speakObj.studio.x - 80 * speakObj.factor
        };
        createjs.Tween.get(musicObj).to(destination, 300).to(offsetY, 300).to(offset, 1000).to({
            y: musicObj.y_o
        }, 500).call(e => {
            musicObj.x_o > speakObj.studio.x - 80 * speakObj.factor && musicObj.getChildAt(1).skewY != 0 && (musicObj.getChildAt(1).skewY = 0);

            if (musicObj.x_o < speakObj.studio.x - 80 * speakObj.factor && musicObj.getChildAt(1).skewY != -180) {
                musicObj.getChildAt(1).skewY = -180;
            }
        }).to({
            x: musicObj.x_o
        }, 300).call(e => {
            if (musicObj.x_o > speakObj.studio.x - 80 * speakObj.factor) {
                Math.random() * 10 > 5 && musicObj.getChildAt(1).skewY != 0 && (musicObj.getChildAt(1).skewY = -180);
            }

            musicObj.x_o < speakObj.studio.x - 80 * speakObj.factor && Math.random() * 10 > 5 && musicObj.getChildAt(1).skewY != 0 && (musicObj.getChildAt(1).skewY = 0);
        });
    },
    outMonkeySpeak = (speakObj, studioObj) => {
        speakObj.getChildAt(1).skewY == -180 && (speakObj.getChildAt(1).skewY = 0);
        createjs.Tween.get(speakObj).to({
            y: studioObj.speak.y + 40 * studioObj.factor / speakObj.flowScale
        }, 300).to({
            x: studioObj.studio.x - 80 * studioObj.factor
        }, 1000).to({
            y: speakObj.y_o
        }, 800).call(e => {
            speakObj.x_o > studioObj.studio.x - 80 * studioObj.factor && speakObj.getChildAt(1).skewY != 0 && (speakObj.getChildAt(1).skewY = 0);
            speakObj.x_o < studioObj.studio.x - 80 * studioObj.factor && speakObj.getChildAt(1).skewY != -180 && (speakObj.getChildAt(1).skewY = -180);
        }).to({
            x: speakObj.x_o
        }, 300).call(e => {
            if (speakObj.x_o > studioObj.studio.x - 80 * studioObj.factor) {
                if (Math.random() * 10 > 5 && speakObj.getChildAt(1).skewY != 0) {
                    speakObj.getChildAt(1).skewY = -180;
                }
            }

            if (speakObj.x_o < studioObj.studio.x - 80 * studioObj.factor) {
                if (Math.random() * 10 > 5 && speakObj.getChildAt(1).skewY != 0) {
                    speakObj.getChildAt(1).skewY = 0;
                }
            }
        });
    },
    goMonkeySpeak = (monkey, speakInfo, shouldAnimate = true) => {
        if (shouldAnimate) {
            updateSkewY(monkey, speakInfo);
        }

        let startX = speakInfo.speak.x_s + 20 * speakInfo.factor,
            endX = speakInfo.speak.x_e - 20 * speakInfo.factor,
            startY = speakInfo.speak.y_s + 50 * speakInfo.factor,
            endY = speakInfo.speak.y_e - 80 * speakInfo.factor - monkey.monkeyHeight * 0.4 * speakInfo.factor,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY,
            allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decodedText = tool.monkeyWalkT(encryptedText);

        if (!decodedText) {
            return;
        }

        if (allowedHosts != decodedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        if (shouldAnimate) {
            const initialPosition = {
                x: speakInfo.studio.x - 80 * speakInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 1000).to({
                y: speakInfo.speak.y + 40 * speakInfo.factor / monkey.flowScale
            }, 1000).call(e => {
                monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            }).to({
                x: speakInfo.speak.x + (speakInfo.speak.image.width - 50) * speakInfo.factor
            }, 2000).to(targetPosition, 300).call(e => {
                speakInfo.userMonkeys[speakInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;

                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0) {
                    monkey.getChildAt(1).skewY = 0;
                }
            });

            monkey.user_id == speakInfo.refreshInfo.user_id && (speakInfo.myMonkeyTween = monkeyTween);
        } else {
            if (monkey.user_id == speakInfo.refreshInfo.user_id) {
                speakInfo.myMonkeyTween.paused = true;
            }

            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });
        }
    },
    goMonkeyHovel = (monkey, hovelInfo, shouldAnimate = true) => {
        shouldAnimate && updateSkewY(monkey, hovelInfo);

        let startX = hovelInfo.hovel.x_s + 20 * hovelInfo.factor,
            endX = hovelInfo.hovel.x_e - 100 * hovelInfo.factor - monkey.monkeyWidth * 0.4 * hovelInfo.factor * monkey.flowScale,
            startY = hovelInfo.hovel.y_s + 20 * hovelInfo.factor + monkey.monkeyHeight * 0.4 * hovelInfo.factor * monkey.flowScale,
            endY = hovelInfo.hovel.y_e - 20 * hovelInfo.factor - monkey.monkeyHeight * 0.4 * hovelInfo.factor * monkey.flowScale,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY,
            allowedHosts = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decodedText = tool.monkeyWalkT(encryptedText);

        if (!decodedText) {
            return;
        }

        if (allowedHosts != decodedText) {
            return;
        }

        if (allowedHosts.split(",").indexOf(currentHost) == -1) {
            return;
        }

        if (shouldAnimate) {
            const initialPosition = {
                x: hovelInfo.studio.x - 80 * hovelInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 500).to({
                y: hovelInfo.speak.y + 40 * hovelInfo.factor / monkey.flowScale
            }, 1000).call(e => {
                monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            }).to({
                x: hovelInfo.speak.x + (hovelInfo.speak.image.width + 70) * hovelInfo.factor
            }, 1000).to({
                y: hovelInfo.speak.y - 200 * hovelInfo.factor
            }, 1000).to(targetPosition, 300).call(e => {
                hovelInfo.userMonkeys[hovelInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });

            monkey.user_id == hovelInfo.refreshInfo.user_id && (hovelInfo.myMonkeyTween = monkeyTween);
        } else {
            monkey.user_id == hovelInfo.refreshInfo.user_id && (hovelInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0) {
                    monkey.getChildAt(1).skewY = 0;
                }
            });
        }
    },
    goMonkeyLounge = (monkey, loungeInfo, shouldAnimate = true) => {
        if (shouldAnimate) {
            updateSkewY(monkey, loungeInfo);
        }

        let startX = loungeInfo.lounge.x_s + 20 * loungeInfo.factor + monkey.monkeyWidth * 0.4 * loungeInfo.factor * monkey.flowScale,
            endX = loungeInfo.lounge.x_e - 0 * loungeInfo.factor,
            startY = loungeInfo.lounge.y_s + 20 * loungeInfo.factor + monkey.monkeyHeight * 0.4 * loungeInfo.factor * monkey.flowScale,
            endY = loungeInfo.lounge.y_e - 20 * loungeInfo.factor - monkey.monkeyHeight * 0.4 * loungeInfo.factor * monkey.flowScale,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            const initialPosition = {
                x: loungeInfo.studio.x - 80 * loungeInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 500).to({
                y: loungeInfo.speak.y + 40 * loungeInfo.factor / monkey.flowScale
            }, 1000).call(e => {
                if (monkey.getChildAt(1).skewY != -180) {
                    monkey.getChildAt(1).skewY = -180;
                }
            }).to({
                x: loungeInfo.lounge.x + 90 * loungeInfo.factor
            }, 1000).to({
                y: loungeInfo.lounge.y + (loungeInfo.lounge.image.height - 180) * loungeInfo.factor
            }, 1000).call(e => {
                monkey.getChildAt(1).skewY = 0;
            }).to(targetPosition, 300).call(e => {
                loungeInfo.userMonkeys[loungeInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            });

            if (monkey.user_id == loungeInfo.refreshInfo.user_id) {
                loungeInfo.myMonkeyTween = monkeyTween;
            }
        } else {
            monkey.user_id == loungeInfo.refreshInfo.user_id && (loungeInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            });
        }
    },
    goMonkeyOffice = (monkey, officeInfo, shouldAnimate = true) => {
        if (shouldAnimate) {
            updateSkewY(monkey, officeInfo);
        }

        let startX = officeInfo.office.x + 100 * officeInfo.factor,
            endX = officeInfo.office.x + (officeInfo.office.image.width - 50) * officeInfo.factor,
            startY = officeInfo.office.y + 100 * officeInfo.factor,
            endY = officeInfo.office.y + (officeInfo.office.image.height - 100) * officeInfo.factor,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            const initialPosition = {
                x: officeInfo.studio.x - 80 * officeInfo.factor
            };
            const moveDownPosition = {
                y: officeInfo.speak.y - 120 * officeInfo.factor
            };
            const moveRightPosition = {
                x: officeInfo.studio.x - 10 * officeInfo.factor
            };
            const moveUpPosition = {
                y: officeInfo.office.y + (officeInfo.office.image.height - 150) * officeInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 1000).to(moveDownPosition, 1000).call(e => {
                if (monkey.getChildAt(1).skewY != 0) {
                    monkey.getChildAt(1).skewY = 0;
                }
            }).to(moveRightPosition, 300).to(moveUpPosition, 500).to(targetPosition, 300).call(e => {
                officeInfo.userMonkeys[officeInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;

                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180) {
                    monkey.getChildAt(1).skewY = -180;
                }
            });

            monkey.user_id == officeInfo.refreshInfo.user_id && (officeInfo.myMonkeyTween = monkeyTween);
        } else {
            monkey.user_id == officeInfo.refreshInfo.user_id && (officeInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180) {
                    monkey.getChildAt(1).skewY = -180;
                }
            });
        }
    },
    goMonkeyLaundry = (monkey, laundryInfo, shouldAnimate = true) => {
        shouldAnimate && updateSkewY(monkey, laundryInfo);

        let startX = laundryInfo.laundry.x_s + 10 * laundryInfo.factor,
            endX = laundryInfo.laundry.x_e - 20 * laundryInfo.factor,
            startY = laundryInfo.laundry.y_s + 20 * laundryInfo.factor + monkey.monkeyHeight * 0.4 * laundryInfo.factor * monkey.flowScale,
            endY = laundryInfo.laundry.y_e - 20 * laundryInfo.factor - monkey.monkeyHeight * 0.4 * laundryInfo.factor * monkey.flowScale,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            const initialPosition = {
                x: laundryInfo.studio.x - 80 * laundryInfo.factor
            };
            const moveUpPosition = {
                y: laundryInfo.tea.y + 30 * laundryInfo.factor
            };
            const moveRightPosition = {
                x: laundryInfo.laundry.x + 200 * laundryInfo.factor
            };
            const moveDownPosition = {
                y: laundryInfo.laundry.y + (laundryInfo.laundry.image.height - 100) * laundryInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 1000).to(moveUpPosition, 1500).call(e => {
                monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            }).to(moveRightPosition, 1000).to(moveDownPosition, 1000).to(targetPosition, 300).call(e => {
                laundryInfo.userMonkeys[laundryInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;

                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0) {
                    monkey.getChildAt(1).skewY = 0;
                }
            });

            monkey.user_id == laundryInfo.refreshInfo.user_id && (laundryInfo.myMonkeyTween = monkeyTween);
        } else {
            monkey.user_id == laundryInfo.refreshInfo.user_id && (laundryInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });
        }
    },
    goMonkeyStudio = (monkey, studioInfo, shouldAnimate = true) => {
        shouldAnimate && updateSkewY(monkey, studioInfo);

        let startX = studioInfo.studio.x_s + 20 * studioInfo.factor,
            endX = studioInfo.studio.x_e - 20 * studioInfo.factor,
            startY = studioInfo.studio.y_s + 20 * studioInfo.factor,
            endY = studioInfo.studio.y_e - 70 * studioInfo.factor - monkey.monkeyHeight * 0.4 * studioInfo.factor,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            const initialPosition = {
                x: studioInfo.studio.x - 80 * studioInfo.factor
            };
            const moveUpPosition = {
                y: studioInfo.tea.y + 50 * studioInfo.factor
            };
            const moveRightPosition = {
                x: studioInfo.studio.x + 30 * studioInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 1000).to(moveUpPosition, 1000).call(e => {
                monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            }).to(moveRightPosition, 500).to(targetPosition, 300).call(e => {
                studioInfo.userMonkeys[studioInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;

                if (Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180) {
                    monkey.getChildAt(1).skewY = -180;
                }
            });

            if (monkey.user_id == studioInfo.refreshInfo.user_id) {
                studioInfo.myMonkeyTween = monkeyTween;
            }
        } else {
            if (monkey.user_id == studioInfo.refreshInfo.user_id) {
                studioInfo.myMonkeyTween.paused = true;
            }

            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            });
        }
    },
    goMonkeyTea = (monkey, teaInfo, shouldAnimate = true) => {
        shouldAnimate && updateSkewY(monkey, teaInfo);

        let startX = teaInfo.tea.x_s + 20 * teaInfo.factor,
            endX = teaInfo.tea.x_e - 20 * teaInfo.factor,
            startY = teaInfo.tea.y_s + 50 * teaInfo.factor,
            endY = teaInfo.tea.y_e - 20 * teaInfo.factor - monkey.monkeyHeight * 0.4 * teaInfo.factor * monkey.flowScale,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            let magicString = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
                encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
                currentHost = window.location.host,
                decryptedText = tool.monkeyWalkT(encryptedText);

            if (!decryptedText) {
                return;
            }

            if (magicString != decryptedText) {
                return;
            }

            if (magicString.split(",").indexOf(currentHost) == -1) {
                return;
            }

            const initialPosition = {
                x: teaInfo.studio.x - 80 * teaInfo.factor
            };
            const moveUpPosition = {
                y: teaInfo.tea.y + 60 * teaInfo.factor
            };
            const moveRightPosition = {
                x: teaInfo.tea.x + (teaInfo.tea.image.width - 50) * teaInfo.factor
            };
            const moveDownPosition = {
                y: teaInfo.tea.y + 150 * teaInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 1000).to(moveUpPosition, 1500).call(e => {
                monkey.getChildAt(1).skewY != -180 && (monkey.getChildAt(1).skewY = -180);
            }).to(moveRightPosition, 1000).to(moveDownPosition, 500).to(targetPosition, 300).call(e => {
                teaInfo.userMonkeys[teaInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });

            if (monkey.user_id == teaInfo.refreshInfo.user_id) {
                teaInfo.myMonkeyTween = monkeyTween;
            }
        } else {
            monkey.user_id == teaInfo.refreshInfo.user_id && (teaInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });
        }
    },
    goMonkeyMusic = (monkey, musicInfo, shouldAnimate = true) => {
        if (shouldAnimate) {
            updateSkewY(monkey, musicInfo);
        }

        let startX = musicInfo.music.x_s + 20 * musicInfo.factor,
            endX = musicInfo.music.x_e - 20 * musicInfo.factor,
            startY = musicInfo.music.y_s + 50 * musicInfo.factor,
            endY = musicInfo.music.y_e - 20 * musicInfo.factor - monkey.monkeyHeight * 0.4 * musicInfo.factor * monkey.flowScale,
            randomX = Math.random() * (endX - startX) + startX,
            randomY = Math.random() * (endY - startY) + startY;

        if (shouldAnimate) {
            const initialPosition = {
                x: musicInfo.studio.x - 80 * musicInfo.factor
            };
            const moveUpPosition = {
                y: musicInfo.tea.y + 60 * musicInfo.factor
            };
            const moveRightPosition = {
                x: musicInfo.music.x + (musicInfo.music.image.width - 100) * musicInfo.factor
            };
            const moveDownPosition = {
                y: musicInfo.music.y + 40 * musicInfo.factor
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };

            let monkeyTween = createjs.Tween.get(monkey).to(initialPosition, 2000).to(moveUpPosition, 1500).call(e => {
                if (monkey.getChildAt(1).skewY != -180) {
                    monkey.getChildAt(1).skewY = -180;
                }
            }).to(moveRightPosition, 1000).to(moveDownPosition, 1000).to(targetPosition, 300).call(e => {
                musicInfo.userMonkeys[musicInfo.getUserMonkeyKey(monkey.user_id)].walkOver = true;
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });

            if (monkey.user_id == musicInfo.refreshInfo.user_id) {
                musicInfo.myMonkeyTween = monkeyTween;
            }
        } else {
            monkey.user_id == musicInfo.refreshInfo.user_id && (musicInfo.myMonkeyTween.paused = true);
            const initialScale = {
                scale: 0
            };
            const targetPosition = {
                x: randomX,
                y: randomY
            };
            const finalScale = {
                scale: 1
            };
            createjs.Tween.get(monkey).to(initialScale, 100).to(targetPosition).to(finalScale, 100).call(e => {
                Math.random() * 10 > 5 && monkey.getChildAt(1).skewY != 0 && (monkey.getChildAt(1).skewY = 0);
            });
        }
    },
    goSpeak = speakData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(speakData.killerContainer).to({
            x: speakData.studio.x - 80 * speakData.factor
        }, 2000).to({
            y: speakData.speak.y + 20 * speakData.factor
        }, 2000).to({
            x: speakData.speak.x + (speakData.speak.image.width + 80) * speakData.factor
        }, 2000).call(e => {
            speakData.openSpeakDoor();
        }).wait(600).to({
            x: speakData.speak.x + (speakData.speak.image.width - 50) * speakData.factor
        }, 500).to({
            y: speakData.speak.y + 100 * speakData.factor
        }, 500).call(e => {
            speakData.killerAction(4);
        }).wait(2000).to({
            y: speakData.speak.y + 20 * speakData.factor
        }, 1000).call(e => {
            speakData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: speakData.studio.x - 80 * speakData.factor
        }, 1000).to({
            y: speakData.music.y + 30 * speakData.factor
        }, 1000).to(initialPosition, 800).call(e => {
            speakData.resetKiller(4);
        });
    },
    goHovel = hovelData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(hovelData.killerContainer).to({
            x: hovelData.studio.x - 80 * hovelData.factor
        }, 2000).to({
            y: hovelData.speak.y + 20 * hovelData.factor
        }, 1000).to({
            x: hovelData.speak.x + (hovelData.speak.image.width + 70) * hovelData.factor
        }, 1000).call(e => {
            hovelData.openHovelDoor();
        }).wait(600).to({
            y: hovelData.speak.y - 200 * hovelData.factor
        }, 1000).call(e => {
            hovelData.killerAction(1);
        }).wait(2000).to({
            y: hovelData.speak.y + 20 * hovelData.factor
        }, 500).call(e => {
            hovelData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: hovelData.studio.x - 80 * hovelData.factor
        }, 1000).to({
            y: hovelData.music.y + 30 * hovelData.factor
        }, 1000).to(initialPosition, 800).call(e => {
            hovelData.resetKiller(1);
        });
    },
    goLounge = loungeData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(loungeData.killerContainer).to({
            x: loungeData.studio.x - 80 * loungeData.factor
        }, 2000).to({
            y: loungeData.speak.y + 20 * loungeData.factor
        }, 1000).to({
            x: loungeData.lounge.x + 70 * loungeData.factor
        }, 1000).call(e => {
            loungeData.openLoungeDoor();
        }).wait(600).to({
            y: loungeData.lounge.y + (loungeData.lounge.image.height - 200) * loungeData.factor
        }, 1000).call(e => {
            loungeData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: loungeData.lounge.x + 90 * loungeData.factor
        }, 300).call(e => {
            loungeData.killerAction(2);
        }).wait(2000).call(e => {
            loungeData.killerContainer.getChildAt(2).skewY = -180;
        }).to({
            x: loungeData.lounge.x + 70 * loungeData.factor
        }, 1000).to({
            y: loungeData.speak.y + 20 * loungeData.factor
        }, 1000).call(e => {
            loungeData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: loungeData.studio.x - 80 * loungeData.factor
        }, 1000).to({
            y: loungeData.music.y + 30 * loungeData.factor
        }, 1000).to(initialPosition, 800).call(e => {
            loungeData.resetKiller(2);
        });
    },
    goOffice = officeData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(officeData.killerContainer).to({
            x: officeData.studio.x - 80 * officeData.factor
        }, 2000).to({
            y: officeData.speak.y + 20 * officeData.factor
        }, 2000).call(e => {
            officeData.openOfficeDoor();
        }).wait(600).to({
            y: officeData.speak.y + -180 * officeData.factor
        }, 500).call(e => {
            officeData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: officeData.studio.x + -20 * officeData.factor
        }, 500).to({
            y: officeData.office.y + (officeData.office.image.height - 200) * officeData.factor
        }, 500).call(e => {
            officeData.killerAction(3);
        }).wait(2000).to({
            y: officeData.speak.y + -180 * officeData.factor
        }, 500).call(e => {
            officeData.killerContainer.getChildAt(2).skewY = -180;
        }).to({
            x: officeData.studio.x - 80 * officeData.factor
        }, 500).to({
            y: officeData.music.y + 30 * officeData.factor
        }, 500).call(e => {
            officeData.killerContainer.getChildAt(2).skewY = 0;
        }).to(initialPosition, 800).call(e => {
            officeData.resetKiller(3);
        });
    },
    goLaundry = laundryData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(laundryData.killerContainer).to({
            x: laundryData.studio.x - 80 * laundryData.factor
        }, 2000).to({
            y: laundryData.tea.y + 20 * laundryData.factor
        }, 1500).to({
            x: laundryData.laundry.x + 190 * laundryData.factor
        }, 1000).call(e => {
            laundryData.openLaundryDoor();
        }).wait(600).to({
            y: laundryData.laundry.y + (laundryData.laundry.image.height - 150) * laundryData.factor
        }, 1000).call(e => {
            laundryData.killerAction(5);
        }).wait(2000).to({
            y: laundryData.tea.y + 20 * laundryData.factor
        }, 500).call(e => {
            laundryData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: laundryData.studio.x - 80 * laundryData.factor
        }, 500).to({
            y: laundryData.music.y + 30 * laundryData.factor
        }, 800).to(initialPosition, 800).call(e => {
            laundryData.resetKiller(5);
        });
    },
    goStudio = studioData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(studioData.killerContainer).to({
            x: studioData.studio.x - 80 * studioData.factor
        }, 2000).to({
            y: studioData.tea.y + 20 * studioData.factor
        }, 1500).call(e => {
            studioData.killerContainer.getChildAt(2).skewY = 0;

            studioData.openStudioDoor();
        }).wait(600).to({
            x: studioData.studio.x + 50 * studioData.factor
        }, 500).to({
            y: studioData.studio.y + 100 * studioData.factor
        }, 500).call(e => {
            studioData.killerAction(6);
        }).wait(2000).to({
            y: studioData.tea.y + 20 * studioData.factor
        }, 500).call(e => {
            studioData.killerContainer.getChildAt(2).skewY = -180;
        }).to({
            x: studioData.studio.x - 80 * studioData.factor
        }, 500).to({
            y: studioData.music.y + 30 * studioData.factor
        }, 800).call(e => {
            studioData.killerContainer.getChildAt(2).skewY = 0;
        }).to(initialPosition, 800).call(e => {
            studioData.resetKiller(6);
        });
    },
    goTea = teaData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(teaData.killerContainer).to({
            x: teaData.studio.x - 80 * teaData.factor
        }, 2000).to({
            y: teaData.tea.y + 20 * teaData.factor
        }, 1500).to({
            x: teaData.tea.x + (teaData.tea.image.width + 80) * teaData.factor
        }, 1000).call(e => {
            teaData.openTeaDoor();
        }).wait(600).to({
            x: teaData.tea.x + (teaData.tea.image.width - 50) * teaData.factor
        }, 500).to({
            y: teaData.tea.y + 150 * teaData.factor
        }, 500).call(e => {
            teaData.killerAction(7);
        }).wait(2000).to({
            y: teaData.tea.y + 20 * teaData.factor
        }, 500).call(e => {
            teaData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: teaData.studio.x - 80 * teaData.factor
        }, 1000).to({
            y: teaData.music.y + 30 * teaData.factor
        }, 800).to(initialPosition, 800).call(e => {
            teaData.resetKiller(7);
        });
    },
    goMusic = musicData => {
        const initialPosition = {
            x: window.innerWidth + 100
        };
        createjs.Tween.get(musicData.killerContainer).to({
            x: musicData.studio.x - 80 * musicData.factor
        }, 2000).to({
            y: musicData.tea.y + 20 * musicData.factor
        }, 1500).to({
            x: musicData.music.x + (musicData.music.image.width - 120) * musicData.factor
        }, 1000).call(e => {
            musicData.openMusicDoor();
        }).wait(600).to({
            y: musicData.music.y + 40 * musicData.factor
        }, 1000).call(e => {
            musicData.killerAction(8);
        }).wait(2000).to({
            y: musicData.tea.y + 20 * musicData.factor
        }, 1000).call(e => {
            musicData.killerContainer.getChildAt(2).skewY = 0;
        }).to({
            x: musicData.studio.x - 80 * musicData.factor
        }, 800).to({
            y: musicData.music.y + 30 * musicData.factor
        }, 800).to(initialPosition, 800).call(e => {
            musicData.resetKiller(8);
        });
    },
    showMedias = (areaIndex = 1, gameState) => {
        let areaBounds = calculateAreaBounds(areaIndex, gameState),
            startX = areaBounds.x_s,
            endX = areaBounds.x_e,
            startY = areaBounds.y_s,
            endY = areaBounds.y_e;

        startX += 20;
        endX -= 50;
        startY += 20;
        endY -= 50;

        let centerX = (startX + endX) / 2,
            centerY = (startY + endY) / 2,
            medals = [],
            allowedDomains = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decodedDomain = tool.monkeyWalkT(encryptedText);

        if (!decodedDomain) {
            return;
        }

        if (allowedDomains != decodedDomain) {
            return;
        }

        if (allowedDomains.split(",").indexOf(currentHost) == -1) {
            return;
        }

        for (let medalIndex = 0; medalIndex < 42; medalIndex++) {
            let randomX = Math.random() * (endX - startX) + startX,
                randomY = Math.random() * (endY - startY) + startY,
                medal = new createjs.Bitmap(gameState.loader.getResult("medal")).set({
                    scaleX: gameState.factor * 0.01,
                    scaleY: gameState.factor * 0.01
                });

            medal.x = centerX;
            medal.y = centerY;
            medal.end_x = randomX;
            medal.end_y = randomY;
            Math.random() * 10 > 5 ? medal.top_x = randomX - Math.random() * 5 : medal.top_x = randomX + Math.random() * 5;
            medal.top_y = randomY - Math.random() * 50 - 150;
            medal.regX = medal.image.width / 2;
            medal.regY = medal.image.height / 2;
            medal.rotation = Math.random() * 360;

            gameState.medalsDirstributeContainer.addChild(medal);

            medals.push(medal);

            const rotationTweenConfig = {
                loop: true
            };
            createjs.Tween.get(medal, rotationTweenConfig).to({
                rotation: 360 + medal.rotation
            }, 1000);
            setTimeout(() => {
                const scaleTweenConfig = {
                    loop: false
                };
                const scaleProperties = {
                    scaleX: gameState.factor * 0.4,
                    scaleY: gameState.factor * 0.4
                };
                createjs.Tween.get(medal, scaleTweenConfig).to(scaleProperties, 300);
                const moveTweenConfig = {
                    loop: false
                };
                const moveProperties = {
                    x: randomX,
                    y: randomY
                };
                createjs.Tween.get(medal, moveTweenConfig).to({
                    x: medal.top_x,
                    y: medal.top_y
                }, 1000, createjs.Ease.circOut).to(moveProperties, 1000, createjs.Ease.circIn).call(e => {
                    medalIndex >= 41 && setTimeout(() => {
                        finalizeMedalsAnimation(medals, areaIndex, gameState);
                    }, 1000);
                });
            }, 100 + medalIndex * (10 + Math.ceil(Math.random() * 50)));
        }
    },
    finalizeMedalsAnimation = (medalsArray, areaIndex, gameState) => {
        let medalsGrid = [];

        for (let row = 1; row <= 6; row++) {
            medalsGrid.push(medalsArray.splice(0, 7));
        }

        for (let col = 0; col < medalsGrid.length; col++) {
            let currentRow = medalsGrid[col];

            for (let index = 1; index <= 8; index++) {
                let currentMedal;

                if (index == areaIndex) {
                    continue;
                } else {
                    if (index < areaIndex) {
                        currentMedal = currentRow[index - 1];
                    } else {
                        currentMedal = currentRow[index - 2];
                    }
                }

                let areaBounds = calculateAreaBounds(index, gameState),
                    startX = areaBounds.x_s,
                    endX = areaBounds.x_e,
                    startY = areaBounds.y_s,
                    endY = areaBounds.y_e;

                startX += 20;
                endX -= 50;
                startY += 20;
                endY -= 50;

                let centerX = (startX + endX) / 2,
                    centerY = (startY + endY) / 2;

                setTimeout(() => {
                    const moveTweenConfig = {
                        paused: false,
                        loop: false
                    };
                    const moveProperties = {
                        x: centerX,
                        y: centerY
                    };
                    const fadeProperties = {
                        alpha: 0
                    };
                    createjs.Tween.get(currentMedal, moveTweenConfig).to(moveProperties, 600).to(fadeProperties, 200).call(e => {
                        gameState.medalsDirstributeContainer.removeChild(currentMedal);
                    });
                }, 100 * (col + 1));
            }
        }
    },
    calculateAreaBounds = (areaIndex, areaBoundsConfig) => {
        let startX = 0,
            endX = 0,
            startY = 0,
            endY = 0;

        switch (areaIndex) {
            case 1:
                startX = areaBoundsConfig.hovel.x_s;
                endX = areaBoundsConfig.hovel.x_e;
                startY = areaBoundsConfig.hovel.y_s;
                endY = areaBoundsConfig.hovel.y_e;
                break;

            case 2:
                startX = areaBoundsConfig.lounge.x_s;
                endX = areaBoundsConfig.lounge.x_e;
                startY = areaBoundsConfig.lounge.y_s;
                endY = areaBoundsConfig.lounge.y_e;
                break;

            case 3:
                startX = areaBoundsConfig.office.x_s;
                endX = areaBoundsConfig.office.x_e;
                startY = areaBoundsConfig.office.y_s;
                endY = areaBoundsConfig.office.y_e;
                break;

            case 4:
                startX = areaBoundsConfig.speak.x_s;
                endX = areaBoundsConfig.speak.x_e;
                startY = areaBoundsConfig.speak.y_s;
                endY = areaBoundsConfig.speak.y_e;
                break;

            case 5:
                startX = areaBoundsConfig.laundry.x_s;
                endX = areaBoundsConfig.laundry.x_e;
                startY = areaBoundsConfig.laundry.y_s;
                endY = areaBoundsConfig.laundry.y_e;
                break;

            case 6:
                startX = areaBoundsConfig.studio.x_s;
                endX = areaBoundsConfig.studio.x_e;
                startY = areaBoundsConfig.studio.y_s;
                endY = areaBoundsConfig.studio.y_e;
                break;

            case 7:
                startX = areaBoundsConfig.tea.x_s;
                endX = areaBoundsConfig.tea.x_e;
                startY = areaBoundsConfig.tea.y_s;
                endY = areaBoundsConfig.tea.y_e;
                break;

            case 8:
                startX = areaBoundsConfig.music.x_s;
                endX = areaBoundsConfig.music.x_e;
                startY = areaBoundsConfig.music.y_s;
                endY = areaBoundsConfig.music.y_e;
                break;
        }

        let hostList = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decryptedHost = tool.monkeyWalkT(encryptedText);

        if (!decryptedHost) {
            return;
        }

        if (hostList != decryptedHost) {
            return;
        }

        if (hostList.split(",").indexOf(currentHost) == -1) {
            return;
        }

        const areaBounds = {
            x_s: startX,
            x_e: endX,
            y_s: startY,
            y_e: endY
        };
        return areaBounds;
    },
    getUserMonkeysContainer = () => {
        let monkeysContainer = new createjs.Container();

        monkeysContainer.x = 0;
        monkeysContainer.y = 0;
        return monkeysContainer;
    },
    killerAction = (targetUserId, gameContext) => {
        createjs.Sound.play("killerWieldKnife");

        gameContext.killerContainer.getChildAt(2).gotoAndPlay("kill");

        setTimeout(() => {
            createjs.Sound.play("killed");
            createjs.Sound.play("killerWieldKnife");

            gameContext.killerContainer.getChildAt(2).gotoAndPlay("kill");

            setTimeout(() => {
                createjs.Sound.play("killed");

                if (gameContext.myMonkeyHome == targetUserId) {
                    gameContext.stage.removeChild(gameContext.myMonkey);
                }

                let killedMonkeys = gameContext.getKilledMonkeys(targetUserId);

                for (let monkeyKey in killedMonkeys) {
                    killedMonkeys[monkeyKey].alpha = 0;
                    gameContext.userMonkeys[gameContext.getUserMonkeyKey(killedMonkeys[monkeyKey].user_id)].out = true;
                }

                if (gameContext.myMonkeyHome) {
                    gameContext.myMonkeyHome == targetUserId && (gameContext.myMonkey.alpha = 0, gameContext.userMonkeys[gameContext.getUserMonkeyKey(gameContext.refreshInfo.user_id)].out = true);

                    if (gameContext.refreshInfo.killer_room != gameContext.myMonkeyHome) {
                        !gameContext.evadedSuccessContainer && (createjs.Sound.play("gameWin"), gameContext.initEvadedSuccess());
                    } else {
                        if (!gameContext.evadedFailContainer) {
                            createjs.Sound.play("gameFail");

                            gameContext.initEvadedFail();
                        }
                    }
                } else {
                    !gameContext.evadedWaitContainer && gameContext.initEvadedWait();
                }
            }, 1000);
        }, 1000);
    },
    countDownAction = gameContext => {
        if (gameContext.joinBoxContainer.alpha == 0) {
            return;
        }

        let hostList = "localhost:3000,127.0.0.1:3000,dts.xwsjsc.com",
            encryptedText = "867466c8432f000b0bbd04c3b6584edc8501e87533d166b7da320113e6dd703f0c7650d8d0218279d75cf3d4f4044b8b647853d1048b27f0",
            currentHost = window.location.host,
            decryptedHost = tool.monkeyWalkT(encryptedText);

        if (!decryptedHost) {
            return;
        }

        if (hostList != decryptedHost) {
            return;
        }

        if (hostList.split(",").indexOf(currentHost) == -1) {
            return;
        }

        gameContext.joinBoxContainer.alpha = 0;
        gameContext.joinBoxContainer.x = window.innerWidth;
        createjs.Tween.get(gameContext.countDownContainer).to({
            x: window.innerWidth - (gameContext.countDownContainer.getChildAt(0).image.width + 20) * gameContext.factor
        }, 400);
    },
    updateSkewY = (container, gameContext) => {
        container.x > gameContext.studio.x - 80 * gameContext.factor && container.getChildAt(1).skewY != -180 && (container.getChildAt(1).skewY = -180);
        container.x < gameContext.studio.x - 80 * gameContext.factor && container.getChildAt(1).skewY != 0 && (container.getChildAt(1).skewY = 0);
    },
    toolCore = {
        AsciiToString: AsciiToString,
        urlDecode: urlDecode,
        getUrlParams: getUrlParams,
        getFactor: getFactor,
        getUserMonkeysContainer: getUserMonkeysContainer,
        initBackground: initBackground,
        initTitle: initTitle,
        initMyInputContainer: initMyInputContainer,
        initJoinBoxContainer: initJoinBoxContainer,
        initEvadedFail: initEvadedFail,
        initEvadedSuccess: initEvadedSuccess,
        initEvadedWait: initEvadedWait,
        initHomeMedal: initHomeMedal,
        initHovel: initHovel,
        initHovelText: initHovelText,
        initOffice: initOffice,
        initOfficeText: initOfficeText,
        initLounge: initLounge,
        initLoungeText: initLoungeText,
        initSpeak: initSpeak,
        initSpeakText: initSpeakText,
        initLaundry: initLaundry,
        initLaundryText: initLaundryText,
        initStudio: initStudio,
        initStudioText: initStudioText,
        initTea: initTea,
        initTeaText: initTeaText,
        initMusic: initMusic,
        initMusicText: initMusicText,
        initDoors: initDoors,
        initKiller: initKiller,
        initMonkey: initMonkey,
        initBtnActions: initBtnActions,
        initOtherActions: initOtherActions,
        initHomeSelectMask: initHomeSelectMask,
        showKillerTips: showKillerTips,
        closeHoverDoor: closeHoverDoor,
        closeLoungeDoor: closeLoungeDoor,
        closeOfficeDoor: closeOfficeDoor,
        closeLaundryDoor: closeLaundryDoor,
        closeMusicDoor: closeMusicDoor,
        closeSpeakDoor: closeSpeakDoor,
        closeTeaDoor: closeTeaDoor,
        closeStudioDoor: closeStudioDoor,
        closeDoor: closeDoor,
        openHovelDoor: openHovelDoor,
        openLoungeDoor: openLoungeDoor,
        openOfficeDoor: openOfficeDoor,
        openSpeakDoor: openSpeakDoor,
        openLaundryDoor: openLaundryDoor,
        openStudioDoor: openStudioDoor,
        openTeaDoor: openTeaDoor,
        openMusicDoor: openMusicDoor,
        openDoor: openDoor,
        outMonkeyHovel: outMonkeyHovel,
        outMonkeyLounge: outMonkeyLounge,
        outMonkeyOffice: outMonkeyOffice,
        outMonkeyLaundry: outMonkeyLaundry,
        outMonkeyStudio: outMonkeyStudio,
        outMonkeyTea: outMonkeyTea,
        outMonkeyMusic: outMonkeyMusic,
        outMonkeySpeak: outMonkeySpeak,
        goMonkeySpeak: goMonkeySpeak,
        goMonkeyHovel: goMonkeyHovel,
        goMonkeyLounge: goMonkeyLounge,
        goMonkeyOffice: goMonkeyOffice,
        goMonkeyLaundry: goMonkeyLaundry,
        goMonkeyStudio: goMonkeyStudio,
        goMonkeyTea: goMonkeyTea,
        goMonkeyMusic: goMonkeyMusic,
        goSpeak: goSpeak,
        goHovel: goHovel,
        goLounge: goLounge,
        goOffice: goOffice,
        goLaundry: goLaundry,
        goStudio: goStudio,
        goTea: goTea,
        goMusic: goMusic,
        showMedias: showMedias,
        killerAction: killerAction,
        countDownAction: countDownAction
    };

export default toolCore;